home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / QF2.ZIP / COPYTILE.ASM next >
Assembly Source File  |  1995-04-10  |  6KB  |  150 lines

  1. ;*****************************************************************************
  2. ;
  3. ; COPYTILE
  4. ;
  5. ; Copyright (c) 1991-1995 Ted Gruber Software.  All rights reserved.
  6. ;
  7. ; Prototype
  8. ;
  9. ;    void copytile (int tile_number, int column, int row, int page);
  10. ;
  11. ; Description
  12. ;
  13. ;    Copy a 16x16 tile from a fixed position to the specified row and column.
  14. ;    Tiles must be aligned on video memory doublewords (i.e., multiples of 16
  15. ;    horizontal pixels).
  16. ;
  17. ;    This is a specialized version of fg_transfer() that can be used in the
  18. ;    QuickFire demo program. The source and destination video addresses for
  19. ;    each tile are computed in advance (see the Addr256 macro below). While
  20. ;    it is not a general version of such a function, it should be fairly easy
  21. ;    to tailor this function to your specific application's needs.
  22. ;
  23. ; Parameters
  24. ;
  25. ;    tile_number  The tile number to transfer, between 0 and 255.
  26. ;
  27. ;    column       The source column number, between 0 and 21.
  28. ;
  29. ;    row          The source row number, between 0 and 14.
  30. ;
  31. ;    page         The "page" defining the region for the destination row
  32. ;                 and column. It must be 0 or 1.
  33. ;
  34. ; Return value
  35. ;
  36. ;    none
  37. ;
  38. ; Restrictions
  39. ;
  40. ;    This function is designed to work with in real mode with the medium or
  41. ;    large memory models only.
  42. ;
  43. ;    This function supports mode X only (Fastgraph's modes 20 to 23).
  44. ;
  45. ;    The calling program must have called fg_resize(352,727) to change the
  46. ;    video page dimensions to 352x727. The upper 352x240 area is considered
  47. ;    "page 0" and the 352x240 area that follows is considered "page 1".
  48. ;
  49. ;*****************************************************************************
  50.  
  51. arg1      equ     [bp+6]        ; address of tile_number parameter
  52. arg2      equ     [bp+8]        ; address of column parameter
  53. arg3      equ     [bp+10]       ; address of row parameter
  54. arg4      equ     [bp+12]       ; address of page parameter
  55.  
  56. CT_TEXT   SEGMENT byte public 'CODE'
  57.           ASSUME  cs:CT_TEXT
  58.  
  59. _copytile PROC    far
  60.           PUBLIC  _copytile
  61.  
  62.           push    bp            ; save caller's BP register
  63.           mov     bp,sp         ; make BP point to argument list
  64.           push    di            ; save caller's DI register
  65.           push    si            ; save caller's SI register
  66.           cld                   ; set the direction flag to forward
  67.  
  68.           mov     ax,0A000h
  69.           mov     es,ax         ; point ES to start of video memory
  70.  
  71.           mov     dx,03CEh      ; port address for graphics controller index
  72.           mov     ax,0008h      ; use latches and ignore CPU data
  73.           out     dx,ax         ; send the request
  74.  
  75.           mov     dl,0C4h       ; port address for sequence controller index
  76.           mov     ax,0F02h      ; mask to enable all four bit planes
  77.           out     dx,ax         ; send the request
  78.  
  79.           push    ds            ; save caller's data segment
  80.           push    es
  81.           pop     ds            ; point DS to start of video memory
  82.  
  83.           mov     ax,arg1       ; AX = source tile number
  84.           lea     bx,srce256    ; point BX to address table for source tiles
  85.           shl     ax,1          ; convert tile number to table offset
  86.           add     bx,ax         ; point BX to entry for specified tile
  87.           mov     si,cs:[bx]    ; DS:SI = video address for source tile
  88.  
  89.           mov     ax,arg3       ; AL = destination row number
  90.           mov     ah,22         ; AH = number of tiles per row
  91.           mul     ah
  92.           add     ax,arg2       ; AX = destination tile number
  93.           lea     bx,dest256    ; assume we'll transfer from upper page
  94.           mov     dx,arg4       ; DX = page number (0=upper, 1=lower)
  95.           neg     dx            ; DX = 0 if upper page, FFFFh if lower
  96.           and     dx,22*15*2    ; DX = offset to upper or lower table
  97.           add     bx,dx         ; point BX to address table for dest tiles
  98.           shl     ax,1          ; convert tile number to table offset
  99.           add     bx,ax         ; point BX to entry for specified tile
  100.           mov     di,cs:[bx]    ; ES:DI = video address for destination tile
  101.  
  102.           xor     ch,ch         ; zero CH
  103.           mov     ax,352/4-4    ; AX = offset to first tile in next row
  104.           REPT    16
  105.           mov     cl,4          ; four bytes represent 16 pixels
  106.           rep     movsb         ; transfer all 16 pixels of this row
  107.           add     si,ax         ; point source address to next row
  108.           add     di,ax         ; point destination address to next row
  109.           ENDM
  110.  
  111.           pop     ds            ; restore original data segment
  112.           mov     dx,03CEh      ; port address for graphics controller index
  113.           mov     ax,0FF08h     ; set all bits in the bit mask register
  114.           out     dx,ax         ; send the request
  115.  
  116.           xor     ax,ax         ; in case copytile was called as a function
  117.           pop     si            ; restore caller's SI register
  118.           pop     di            ; restore caller's DI register
  119.           pop     bp            ; restore caller's BP register
  120.           ret                   ; return to the caller
  121.  
  122. _copytile ENDP
  123.  
  124. ;-----------------------------------------------------------------------------
  125.  
  126. Addr256   MACRO   start, columns, rows
  127.  
  128. address   =       start
  129.  
  130.           REPT    rows
  131.  
  132.           REPT    columns
  133.           dw      address
  134. address   =       address + 4
  135.           ENDM
  136.  
  137. address   =       (address - 4*columns) + 352/4*16
  138.           ENDM
  139.  
  140.           ENDM
  141.  
  142. ;-----------------------------------------------------------------------------
  143.  
  144. srce256:  Addr256 352/4*480,20,12   ; source tile addresses
  145. dest256:  Addr256 0,22,15           ; destination tile addresses (upper page)
  146.           Addr256 352/4*240,22,15   ; destination tile addresses (lower page)
  147.  
  148. CT_TEXT   ENDS
  149.           END
  150.